using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using Xioa_UI.DataOrigin;

namespace Xioa_UI.Controls;

public class XioaNavButton : ContentControl
{
    // Button Group
    public static readonly DependencyProperty NavButtonProperty =
        DependencyProperty.Register("NavButton", typeof(ObservableCollection<NavButtonItem>), typeof(XioaNavButton));
    public ObservableCollection<NavButtonItem> NavButton
    {
        get => (ObservableCollection<NavButtonItem>)GetValue(NavButtonProperty);
        set => SetValue(NavButtonProperty, value);
    }

    public static readonly DependencyProperty NavItemMarginProperty =
      ElementBase.Property<XioaNavButton, Thickness>("NavItemMarginProperty", new Thickness(10));
    public Thickness NavItemMargin
    {
        get => (Thickness)GetValue(NavItemMarginProperty);
        set => SetValue(NavItemMarginProperty, value);
    }

    //public static readonly DependencyProperty NavItemIconProperty =
    //  ElementBase.Property<XioaNavButton, string>("NavItemMarginProperty", "");
    //public string NavItemIcon
    //{
    //    get => (string)GetValue(NavItemIconProperty);
    //    set => SetValue(NavItemIconProperty, value);
    //}

    public XioaNavButton()
    {
        //this.Loaded += XioaNavButton_Loaded;
    }

    private void XioaNavButton_Loaded(object sender, RoutedEventArgs e)
    {
        ItemsPresenter itemsPresenter = GetVisualChild<ItemsPresenter>(this.GetTemplateChild("XioaItemControl") as ItemsControl);
        Panel itemsPanel = VisualTreeHelper.GetChild(itemsPresenter, 0) as Panel;
        foreach (var item in itemsPanel.Children)
        {
            Style style = (Style)this.FindResource("NavSelectButton");
           

        }
    }

    private void XioaNavButton_Click(object sender, RoutedEventArgs e)
    {

    }



    private static T GetVisualChild<T>(DependencyObject parent) where T : Visual
    {
        T child = default(T);

        int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
        for (int i = 0; i < numVisuals; i++)
        {
            Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
            child = v as T;
            if (child == null)
            {
                child = GetVisualChild<T>(v);
            }
            if (child != null)
            {
                break;
            }
        }
        return child;
    }
}